package cn.com.cym.gamezao.entity.grk;

import cn.com.cym.gamezao.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@Entity
@Accessors(chain = true)
@Table(name ="sample_patient")
@ApiModel(description = "患者信息")
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
public class Patient extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 6869927739010185752L;

    /**
     * 1门诊2住院
     */
    @Column(length = 10)
    private String type;

    /**
     * 登记号
     */
    @Column(length = 10)
    private String regNum;

    /**
     * 姓名
     */
    @Column(length = 60)
    private String name;

    /**
     * 性别
     */
    @Column(length = 4)
    private String sex;

    /**
     * 证件号
     */
    @Column(length = 26)
    private String idNo;

    /**
     * 电话号码
     */
    @Column(length = 16)
    private String phone;

    /**
     * 身高
     */
    private Double height;


    /**
     * 体重
     */
    private Double weight;


    /**
     * 出生日期
     */
    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(name = "birthday",value = "出生日期",dataType = "LocalDate")
    private LocalDate birthday;


    /**
     * 备注
     */
    @Column(length = 600)
    private String memo;

    @Transient
    private Integer age;

    public Integer getAge(){
        //判断当前数据
        if(this.birthday == null){
            return null;
        }else{
            // LocalDate.now();
            Long until = this.birthday.until(LocalDate.now(), ChronoUnit.YEARS);
            return until.intValue();
        }
    }

    //@OneToMany(mappedBy="patient",fetch = FetchType.EAGER)
    //@JsonProperty(access = JsonProperty.Access.READ_WRITE)
    //private List<Diagnose> diagnoses;
}
